package com.whfp.coky.ui.main.vm

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import com.whfp.coky.databinding.FragFixedBinding
import com.whfp.coky.other.Constants
import com.whfp.coky.ui.base.BaseFragment
import com.whfp.coky.ui.base.model.RequestBean
import com.whfp.coky.ui.base.vm.RecycleVM
import com.whfp.coky.ui.main.frag.TaskFixedFrag
import com.whfp.coky.ui.main.model.DruggerBean
import com.whfp.coky.ui.main.model.TaskCount01Bean

/**
 *
 * 固定任务
 *
 * created by coky on 2022/3/3
 */
class TaskFixedFragVM : RecycleVM<FragFixedBinding, DruggerBean>() {


    override suspend fun httpBlock(page: Int) = httpUtil.doTaskList01(mRequest.value as ReqDruggers)

    var taskCountLD = MutableLiveData<TaskCount01Bean>()

    override fun httpDatas(page: Int) {
        super.httpDatas(page)
        if (page == Constants.PAGE_INDEX){
            launch({httpUtil.doTaskCount01()},taskCountLD,false)
        }
    }


    override fun observe(fragment: BaseFragment<*, *>, owner: LifecycleOwner) {
        super.observe(fragment, owner)
        taskCountLD.observe(fragment, Observer {
            (fragment as TaskFixedFrag).initTaskCount(it)
        })
    }

    override fun getStatusLayout() = vBinding.statusHint

    /**
     * 装载查询数据，启动列表查询
     */
    override fun buildRequest() {
        mRequest.value = ReqDruggers().apply {
            this.realName = ""
        }
    }

    fun changeReq(realName:String) {
        if (realName.isEmpty()){
            buildRequest()
        }else{
            mRequest.value =  ReqDruggers().apply {
                this.realName = realName
            }
        }
    }

    /**
     * 人员列表bean
     */
    class ReqDruggers: RequestBean(){
         var realName:String = ""
        override fun toString(): String {
            return "realName:${realName}"
        }
    }
}